home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / formats / spc.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  2KB  |  75 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. import os
  5. from quodlibet.formats._audio import AudioFile
  6. extensions = [
  7.     '.spc']
  8.  
  9. class SPCFile(AudioFile):
  10.     format = 'SPC700'
  11.     
  12.     def __init__(self, filename):
  13.         h = open(filename, 'rb')
  14.         
  15.         try:
  16.             head = h.read(46)
  17.             if len(head) != 46 or head[:27] != 'SNES-SPC700 Sound File Data':
  18.                 raise IOError('Not a valid SNES-SPC700 file')
  19.             if head[35] == '\x1a':
  20.                 data = h.read(210)
  21.                 if len(data) == 210:
  22.                     self.update(parse_id666(data))
  23.                 
  24.         finally:
  25.             h.close()
  26.  
  27.         self.setdefault('title', os.path.basename(filename)[:-4])
  28.         self.sanitize(filename)
  29.  
  30.     
  31.     def write(self):
  32.         pass
  33.  
  34.     
  35.     def can_change(self, k = None):
  36.         TAGS = [
  37.             'artist',
  38.             'album',
  39.             'title',
  40.             'comments']
  41.         if k is None:
  42.             return TAGS
  43.         return None in TAGS
  44.  
  45.  
  46.  
  47. def parse_id666(data):
  48.     tags = { }
  49.     tags['title'] = data[:32]
  50.     tags['album'] = data[32:64]
  51.     tags['dumper'] = data[64:80]
  52.     tags['comments'] = data[80:112]
  53.     if data[130] < 'A':
  54.         
  55.         try:
  56.             tags['~#length'] = int(data[123:126].strip('\x00'))
  57.         except ValueError:
  58.             pass
  59.  
  60.         tags['artist'] = data[131:163]
  61.     else:
  62.         tags['artist'] = data[130:162]
  63.     for k in tags.keys():
  64.         if k[:2] == '~#':
  65.             continue
  66.         tags[k] = tags[k].replace('\x00', '').decode('ascii', 'ignore')
  67.         if not tags[k]:
  68.             del tags[k]
  69.             continue
  70.     return tags
  71.  
  72. info = SPCFile
  73. types = [
  74.     SPCFile]
  75.